//
//  ThemeTabBar.m
//  微blog
//
//  Created by Jorn.Wu on 15/8/21.
//  Copyright (c) 2015年 Jorn.Wu(jorn_wza@sina.com). All rights reserved.
//

#import "ThemeTabBar.h"
#import "ThemeManager.h"

@implementation ThemeTabBar

/**
 * 重写dealloc方法，旨在移除观察者
 */
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeDidChangedNotification object:nil];
}


/**
 * 重写initWithFrame方法，旨在让tabbar可以响应切换主题通知
 */
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        /**
         * 注册成为接收者
         */
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChangedNotificationAction:) name:kThemeDidChangedNotification object:nil];
    }
    
    return self;
    
}


/**
 * 重写awakeFromNib方法，旨在方便XIB创建
 */
- (void)awakeFromNib{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChangedNotificationAction:) name:kThemeDidChangedNotification object:nil];
    
}


/**
 * 通知的响应方法
 */
- (void)themeDidChangedNotificationAction:(NSNotification *)noti{
    [self reloadIamge];
}


/**
 * 重新加载图片
 */
- (void)reloadIamge{
    ThemeManager *manager = [ThemeManager defualtManager];
    
    /**
     * 通过主题管理对象manager来获取图
     */
    UIImage *image = [manager getThemeImage:self.imageName];
    
    /**
     * 设置图片
     */
    if (image) {
        self.image = image;
    }

}


/**
 * 重新set方法，旨在更改图片
 */
- (void)setImageName:(NSString *)imageName{
    if (![_imageName isEqualToString:imageName]) {
        _imageName = [imageName copy];
        [self reloadIamge];
    }
}






















/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
